//
//  DIYRenterOrderTableViewCell.m
//  UcarTest
//
//  Created by 陈曦 on 16/3/14.
//  Copyright © 2016年 chenxi. All rights reserved.
//

#import "DIYRenterOrderTableViewCell.h"
#import "Define.h"
#import "UIImageView+WebCache.h"
#import "NetRequestGroup.h"



@implementation DIYRenterOrderTableViewCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        
        self.bgView = [[UIView alloc] initWithFrame:CGRectMake(5, 10, kScreenWidth - 10, 200)];
        self.bgView.backgroundColor = [UIColor whiteColor];
        self.bgView.layer.cornerRadius = 2;
        self.bgView.layer.shadowOpacity = 1.0;
        self.bgView.layer.shadowOffset = CGSizeMake(0.0, 0.0);
        self.bgView.layer.shadowColor = [UIColor grayColor].CGColor;
        self.bgView.layer.shadowRadius = 2.0;
        [self addSubview:self.bgView];
        
       //第一部分----------------------------------------------------------
        //车品牌
        self.car_brandLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 15, 30, 15)];
//        self.car_brandLabel.text = @"奥迪";
        self.car_brandLabel.textColor = [UIColor colorWithRed:51 / 255.0 green:51 / 255.0 blue:51 / 255.0 alpha:1];
        self.car_brandLabel.textAlignment = NSTextAlignmentLeft;
        self.car_brandLabel.font = [UIFont systemFontOfSize:15];
        [self.bgView addSubview:self.car_brandLabel];
        
        //车牌照
        self.car_placeLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 15, 70, 15)];
//        self.car_placeLabel.text = @"沪A98**6";
        self.car_placeLabel.textColor = mainColor;
        self.car_placeLabel.textAlignment = NSTextAlignmentCenter;
        self.car_placeLabel.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.car_placeLabel];
        
        //车型号
        self.car_modelLabel = [[UILabel alloc] initWithFrame:CGRectMake(130, 15, 60, 14)];
        self.car_modelLabel.layer.cornerRadius = 2;
        self.car_modelLabel.layer.masksToBounds = YES;
        self.car_modelLabel.backgroundColor = [UIColor orangeColor];
//        self.car_modelLabel.text = @"s350";
        self.car_modelLabel.textAlignment = NSTextAlignmentCenter;
        self.car_modelLabel.textColor = [UIColor whiteColor];
        self.car_modelLabel.font = [UIFont systemFontOfSize:13];
        [self.bgView addSubview:self.car_modelLabel];
        
        //变速箱类型
        self.car_speed_boxLabel = [[UILabel alloc] initWithFrame:CGRectMake(208, 15, 40, 14)];
        self.car_speed_boxLabel.layer.cornerRadius = 2;
        self.car_speed_boxLabel.layer.masksToBounds = YES;
        self.car_speed_boxLabel.backgroundColor = [UIColor grayColor];
//        self.car_speed_boxLabel.text = @"手动";
        self.car_speed_boxLabel.textAlignment = NSTextAlignmentCenter;
        self.car_speed_boxLabel.textColor = [UIColor whiteColor];
        self.car_speed_boxLabel.font = [UIFont systemFontOfSize:13];
        [self.bgView addSubview:self.car_speed_boxLabel];
        
        
        //第二部分----------------------------------------------------------
        //汽车图片
        self.car_left_img_smallImageV = [[UIImageView alloc] initWithFrame:CGRectMake(10, 43, 110, 100)];
        self.car_left_img_smallImageV.backgroundColor = [UIColor grayColor];
        [self.bgView addSubview:self.car_left_img_smallImageV];
        
        //用车时间
        UILabel *useCarLabel = [[UILabel alloc] initWithFrame:CGRectMake(133, 43, 70, 14)];
        useCarLabel.text = @"用车时间:";
        useCarLabel.textAlignment = NSTextAlignmentLeft;
        useCarLabel.textColor = [UIColor colorWithRed:58 / 255.0 green:58 / 255.0 blue:58 / 255.0 alpha:1];
        useCarLabel.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:useCarLabel];
        
        self.use_timeShowLabel = [[UILabel alloc] initWithFrame:CGRectMake(210, 43, 100, 14)];
//        self.use_timeShowLabel.text = @"1天";
        self.use_timeShowLabel.textAlignment = NSTextAlignmentLeft;
        self.use_timeShowLabel.textColor = [UIColor colorWithRed:102 / 255.0 green:102 / 255.0 blue:102 / 255.0 alpha:1];
        self.use_timeShowLabel.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.use_timeShowLabel];
        
        //订单金额
        UILabel *moneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(133, 72, 70, 14)];
        moneyLabel.text = @"订单金额:";
        moneyLabel.textAlignment = NSTextAlignmentLeft;
        moneyLabel.textColor = [UIColor colorWithRed:58 / 255.0 green:58 / 255.0 blue:58 / 255.0 alpha:1];
        moneyLabel.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:moneyLabel];
        
        self.total_moneyShowLabel = [[UILabel alloc] initWithFrame:CGRectMake(210, 72, 100, 14)];
//        self.total_moneyShowLabel.text = @"500.00元";
        self.total_moneyShowLabel.textAlignment = NSTextAlignmentLeft;
        self.total_moneyShowLabel.textColor = [UIColor colorWithRed:102 / 255.0 green:102 / 255.0 blue:102 / 255.0 alpha:1];
        self.total_moneyShowLabel.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.total_moneyShowLabel];

        
        //取车时间
        UILabel *begintimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(133, 101, 70, 14)];
        begintimeLabel.text = @"取车时间:";
        begintimeLabel.textAlignment = NSTextAlignmentLeft;
        begintimeLabel.textColor = [UIColor colorWithRed:58 / 255.0 green:58 / 255.0 blue:58 / 255.0 alpha:1];
        begintimeLabel.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:begintimeLabel];
        
        self.open_timeShowLabel = [[UILabel alloc] initWithFrame:CGRectMake(210, 101, 110, 14)];
//        self.open_timeShowLabel.text = @"2015/12/12 15:13";
        self.open_timeShowLabel.textAlignment = NSTextAlignmentLeft;
        self.open_timeShowLabel.textColor = [UIColor colorWithRed:102 / 255.0 green:102 / 255.0 blue:102 / 255.0 alpha:1];
        self.open_timeShowLabel.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.open_timeShowLabel];


        //还车时间
        UILabel *endtimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(133, 130, 70, 14)];
        endtimeLabel.text = @"还车时间:";
        endtimeLabel.textAlignment = NSTextAlignmentLeft;
        endtimeLabel.textColor = [UIColor colorWithRed:58 / 255.0 green:58 / 255.0 blue:58 / 255.0 alpha:1];
        endtimeLabel.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:endtimeLabel];
        
        self.end_timeShowLabel = [[UILabel alloc] initWithFrame:CGRectMake(210, 130, 110, 14)];
//        self.end_timeShowLabel.text = @"2015/12/12 15:13";
        self.end_timeShowLabel.textAlignment = NSTextAlignmentLeft;
        self.end_timeShowLabel.textColor = [UIColor colorWithRed:102 / 255.0 green:102 / 255.0 blue:102 / 255.0 alpha:1];
        self.end_timeShowLabel.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.end_timeShowLabel];

        UIView *demarcationLine8 = [[UIView alloc] initWithFrame:CGRectMake(0, 157, kScreenWidth - 10, 0.5)];//分界线
        demarcationLine8.backgroundColor = lineColor;
        [self.bgView addSubview:demarcationLine8];
        
        
        
 
        
        
        
        
        
    }
    
    return self;
    
}

- (void)setModel:(RenterOrderModel *)model{
    
    _model = model;
    
    NSString *urlStr = [NSString stringWithFormat:@"%@%@", kRealmNameImage,model.car_left_img_small];

    [_car_left_img_smallImageV  sd_setImageWithURL:[NSURL URLWithString:urlStr]];
    
    _car_brandLabel.text = model.car_brand;//车名
    
    _car_placeLabel.text = model.car_place;//车牌
    
    _car_modelLabel.text = model.car_model;//车型
    
    _car_speed_boxLabel.text = model.car_speed_box;//排量
    
    _order_statusStr = model.order_status;//订单状态
    
    [self judgeView];
    
    _use_timeShowLabel.text = [NSString stringWithFormat:@"%@", model.use_time];//用车时间
    _total_moneyShowLabel.text = [NSString stringWithFormat:@"%@元", model.total_money];//订单金额
    
    
    //字符串转换成时间戳
    NSDate *confromTimespOpen = [NSDate dateWithTimeIntervalSince1970:[model.open_time intValue]];
    NSDateFormatter *dateFormatOpen = [[NSDateFormatter alloc]init];
    [dateFormatOpen setDateFormat:@"yyyy/MM/dd HH:mm"];
    self.open_timeShowLabel.text = [dateFormatOpen stringFromDate:confromTimespOpen];

    NSDate *confromTimespEnd = [NSDate dateWithTimeIntervalSince1970:[model.end_time intValue]];
    NSDateFormatter *dateFormatEnd = [[NSDateFormatter alloc]init];
    [dateFormatEnd setDateFormat:@"yyyy/MM/dd HH:mm"];
    self.end_timeShowLabel.text = [dateFormatEnd stringFromDate:confromTimespEnd];
    

    self.add_timeShowLabel.text = model.add_time_str;
    
}

- (void) judgeView {
    
    //第三部分----------------------------------------------------
    if ([self.order_statusStr isEqualToString:@"0"]) {
        
        [self removeView];
        
        //订单状态图片
        self.statusImageV = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth - 43 , 10, 23, 23)];
        self.statusImageV.image = [UIImage imageNamed:@"icon-indent-dai"];
        [self.bgView addSubview:self.statusImageV];
        
        self.pointView = [[UIView alloc] initWithFrame:CGRectMake(10, 173, 10, 10)];
        self.pointView.backgroundColor = mainColor;
        self.pointView.layer.cornerRadius = 5;
        [self.bgView addSubview:self.pointView];
        
        self.renterMoneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 171, 30, 14)];
        self.renterMoneyLabel.text = @"租金";
        self.renterMoneyLabel.textAlignment = NSTextAlignmentCenter;
        self.renterMoneyLabel.textColor = [UIColor colorWithRed:58 / 255.0 green:58 / 255.0 blue:58 / 255.0 alpha:1];
        self.renterMoneyLabel.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.renterMoneyLabel];
        
        self.payBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.payBtn.frame = CGRectMake(kScreenWidth - 82, 168, 62, 23);
        [self.payBtn setTitle:@"去支付" forState:UIControlStateNormal];
        self.payBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [self.payBtn setTitleColor:[UIColor colorWithRed:0 / 255.0 green:137 / 255.0 blue:225 / 255.0 alpha:1] forState:UIControlStateNormal];
        self.payBtn.layer.borderWidth = 0.5;
        self.payBtn.layer.borderColor = [UIColor colorWithRed:0 / 255.0 green:137 / 255.0 blue:225 / 255.0 alpha:1].CGColor;
        self.payBtn.layer.cornerRadius = 3;
        self.payBtn.layer.masksToBounds = YES;
        [self.bgView addSubview:self.payBtn];
        
        
        //时间
        self.add_timeShowLabel = [[UILabel alloc] initWithFrame:CGRectMake(70, 171, 90, 14)];
        self.add_timeShowLabel.textAlignment = NSTextAlignmentCenter;
        self.add_timeShowLabel.textColor = mainColor;
        self.add_timeShowLabel.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.add_timeShowLabel];

        
    } else if ([self.order_statusStr isEqualToString:@"1"]) {
        
        [self removeView];

        //订单状态图片
        self.statusImageV = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth - 43 , 10, 23, 23)];
        self.statusImageV.image = [UIImage imageNamed:@"icon-indent-dai"];
        [self.bgView addSubview:self.statusImageV];
        
        self.waitLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 171, 60, 14)];
        self.waitLabel.text = @"等待确认";
        self.waitLabel.textAlignment = NSTextAlignmentCenter;
        self.waitLabel.textColor = [UIColor colorWithRed:58 / 255.0 green:58 / 255.0 blue:58 / 255.0 alpha:1];
        self.waitLabel.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.waitLabel];
        
    } else if ([self.order_statusStr isEqualToString:@"2"]) {
        
        [self removeView];

        //订单状态图片
        self.statusImageV = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth - 43 , 10, 23, 23)];
        self.statusImageV.image = [UIImage imageNamed:@"icon-indent-dai"];
        [self.bgView addSubview:self.statusImageV];
        
        self.pointView = [[UIView alloc] initWithFrame:CGRectMake(10, 173, 10, 10)];
        self.pointView.backgroundColor = mainColor;
        self.pointView.layer.cornerRadius = 5;
        [self.bgView addSubview:self.pointView];
        
        self.renterMoneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 171, 30, 14)];
        self.renterMoneyLabel.text = @"押金";
        self.renterMoneyLabel.textAlignment = NSTextAlignmentCenter;
        self.renterMoneyLabel.textColor = [UIColor colorWithRed:58 / 255.0 green:58 / 255.0 blue:58 / 255.0 alpha:1];
        self.renterMoneyLabel.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.renterMoneyLabel];
        
        self.payDBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.payDBtn.frame = CGRectMake(kScreenWidth - 82, 168, 62, 23);
        [self.payDBtn setTitle:@"去支付" forState:UIControlStateNormal];
        self.payDBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [self.payDBtn setTitleColor:[UIColor colorWithRed:0 / 255.0 green:137 / 255.0 blue:225 / 255.0 alpha:1] forState:UIControlStateNormal];
        self.payDBtn.layer.borderWidth = 0.5;
        self.payDBtn.layer.borderColor = [UIColor colorWithRed:0 / 255.0 green:137 / 255.0 blue:225 / 255.0 alpha:1].CGColor;
        self.payDBtn.layer.cornerRadius = 3;
        self.payDBtn.layer.masksToBounds = YES;
        [self.bgView addSubview:self.payDBtn];
        
        
    } else if ([self.order_statusStr isEqualToString:@"3"]) {
        
        [self removeView];

        //订单状态图片
        self.statusImageV = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth - 43 , 10, 23, 23)];
        self.statusImageV.image = [UIImage imageNamed:@"icon-indent-yong"];
        [self.bgView addSubview:self.statusImageV];
        
        
    } else if ([self.order_statusStr isEqualToString:@"4"]) {
        
        [self removeView];

        //订单状态图片
        self.statusImageV = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth - 43 , 10, 23, 23)];
        self.statusImageV.image = [UIImage imageNamed:@"icon-indent-wan"];
        [self.bgView addSubview:self.statusImageV];
        
    }

    
}

- (void) removeView {
    
    [self.waitLabel removeFromSuperview];
    [self.payBtn removeFromSuperview];
    [self.statusImageV removeFromSuperview];
    [self.pointView removeFromSuperview];
    [self.renterMoneyLabel removeFromSuperview];
    [self.payDBtn removeFromSuperview];
    [self.add_timeShowLabel removeFromSuperview];
    
}

@end
